//
//  LYLSearchReadCell.m
//  ONE
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 GroupNine. All rights reserved.
//

#import "LYLSearchReadCell.h"

@interface LYLSearchReadCell ()

/** 阅读类型图片视图 */
@property (strong, nonatomic) UIImageView *readTypeView;
/** 标题 */
@property (strong, nonatomic) UILabel *titleLabel;

@end

@implementation LYLSearchReadCell

+ (CGFloat)cellHeight {
    return 64;
}

#pragma mark - View Lifecycle

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        _readTypeView = [UIImageView new];
        _readTypeView.backgroundColor = [UIColor whiteColor];
        _readTypeView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_readTypeView];
        [_readTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@48);
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(self.contentView).offset(8);
        }];
        
        _titleLabel = [UILabel new];
        _titleLabel.backgroundColor = [UIColor whiteColor];
        _titleLabel.font = FontWithSize(17);
        _titleLabel.textColor = LYLLightBlackTextColor;
        [self.contentView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(_readTypeView.mas_right).offset(8);
            make.right.equalTo(self.contentView);
        }];
    }
    
    return self;
}

//- (void)prepareForReuse {
//    [super prepareForReuse];
//    _readTypeView.image = nil;
//}

- (void)setModel:(LYLReadItemModel *)model
{
    if (_model != model) {
        _model = model;
        if ([model.type isEqualToString:@"essay"]) {
            _readTypeView.image = [UIImage imageNamed:@"icon_read"];
        } else if ([model.type isEqualToString:@"serialcontent"]) {
            _readTypeView.image = [UIImage imageNamed:@"icon_serial"];
        } else if ([model.type isEqualToString:@"question"]) {
            _readTypeView.image = [UIImage imageNamed:@"icon_question"];
        } else {
            _readTypeView.image = nil;
        }
        _titleLabel.text = model.title;
    }
}



@end
